package com.mx.tool.form.window.encryption;

import cn.hutool.core.codec.Base64;
import com.mx.tool.util.NewStrUtil;

import javax.swing.*;
import java.nio.charset.Charset;

/**
 * @Author: 徐建鹏.
 * @create: 2021-11-10 08:53
 * @Description:
 */
public class Base64Window {

    private JPanel jPanel;
    private JTextArea contentArea;
    private JTextArea showArea;
    private JButton jamButton;
    private JButton jemButton;
    private JButton clearButton;
    private JButton hhButton;


    public Base64Window() {
        jamButton.addActionListener(e -> showArea.setText(Base64.encode(contentArea.getText(), Charset.defaultCharset())));
        jemButton.addActionListener(e -> showArea.setText(NewStrUtil.newStringUtf8(Base64.decode(contentArea.getText()))));
        clearButton.addActionListener(e -> {
            contentArea.setText("");
            showArea.setText("");
        });
        hhButton.addActionListener(e -> {
            String content = contentArea.getText();
            String show = showArea.getText();
            contentArea.setText(show);
            showArea.setText(content);
        });
    }

    public JPanel getContent() {
        return jPanel;
    }
}
